<?php
/**
 * 管理上传附件
 * 对于上传了的附件而在页面栏目中没有使用的就可以清理掉
 *Author			peace@warmy.cn
 * Create 			2009-03-12
 */
class WAttach extends Athena 
{
	function View_List()
	{
		//记录可编辑，默认记录不可编辑
		$EditCmd	= false;
		$url		= $this->parse_URI("cmd","id");
		$url		= "$url&cmd=edit&id=";
		
		$str = "";
		while (list(,$value) = each($this->vrow)) {
			$str = "$str<tr>";
			$str = "$str<td width=\"0\"><input type=\"checkbox\" name=\"id[]\" value=\"{$value['id']}\"></td>";
			$str = "$str<td>";
			if(eregi("\.(gif|jpg|jpeg|png|bmp)$",$value['src']))
				$str = "$str<a href=\"{$value['src']}\" target=\"_blank\"><img src=\"{$value['src']}\" width=\"50\" height=\"50\" border=\"0\"></a>";
			elseif(eregi("\.swf$",$value['src']))
				$str = "$str<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"50\" height=\"50\">
				  <param name=\"movie\" value=\"{$value['src']}\" />
				  <param name=\"quality\" value=\"high\" />
				  <embed src=\"{$value['src']}\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"50\" height=\"50\"></embed>";
			else 
				$str = "$str<a href=\"{$value['src']}\" target=\"_blank\">{$value['src']}</a>";
			$str = "$str</td>";
			$str = "$str<td>{$value['catalog']}</td>";
			$str = "$str<td>{$value['active']}</td>";
			$str = "$str</tr>";
		}
		return $str;
	}
	function View_Button()
	{
		print("<tr bgcolor=\"#FFFFFF\"><td colspan=\"{$this->vcolspan}\" height=\"50\" style=\"text-align:center\">");
		print("&nbsp;<input name=\"delete\" name=\"Delete\" type=\"Submit\" class=\"button\" value=\"删除\" onclick=\"if(window.confirm('确信删除？')){AppendCmd('delete')}else{return false;}\">");
		print("</td></tr>");
	}
	function Del()
	{
		if(isset($_POST["id"]))
		{
			$str	= implode(",",$_POST["id"]);
			if(ereg("^[0-9,]+$",$str))
			{
				//判断图片是否为本地图片
				$sql = "select src from `{$this->table}` where {$this->primary} in($str)";
				$list = $this->db->query_row($sql,MYSQL_ASSOC);
				while (list(,$value) = each($list)) {
					if(!eregi("^http://",$value['src']))
						@unlink(DOCUMENTROOT.$value['src']);
				}
				$sql		= "delete from `{$this->table}` where {$this->primary} in($str)";
				$this->db->query($sql);
				$this->halt("成功删除选择附件");
			}
			else 
				$this->halt("错误删除参数！");
		}
		else 
			$this->halt("没有选择需要删除的附件");
	}
}
?>